package com.probox.order.api.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.probox.common.core.annotation.Excel;
import com.probox.common.core.enums.*;
import com.probox.common.core.utils.StringUtils;
import com.probox.common.core.utils.money.PriceFormatUtil;
import com.probox.customer.api.domain.CustomerAddressVo;
import com.probox.platform.api.domain.PlatformAddressVo;
import com.probox.supplier.api.domain.SupplierAddressVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@ApiModel(description="订单售后")
public class OrderPostSaleVo implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long serviceUid;
    /** 平台ID */
    @Excel(name = "平台ID")
    @ApiModelProperty(value = "平台ID(平台ID)")
    private Long platformUid;

    /** 订单ID */
    @Excel(name = "订单ID")
    @ApiModelProperty(value = "订单ID(订单ID)")
    private Long orderUid;

    /** 订单编号 */
    @Excel(name = "订单编号")
    @ApiModelProperty(value = "订单编号(订单编号)")
    private String orderNo;

    /** 订单明细 */
    @Excel(name = "订单明细")
    @ApiModelProperty(value = "订单明细(售后必传)")
    private Long itemUid;

    @ApiModelProperty(value = "商品名称")
    private String proName;

    @ApiModelProperty(value = "sku属性值")
    private String skuDesc;

    @ApiModelProperty(value = "封面图")
    private String imgUrl;

    /** 供应商ID */
    @Excel(name = "供应商ID")
    @ApiModelProperty(value = "供应商ID(供应商ID)")
    private Long supplierUid;

    /** 供应商名称 */
    @Excel(name = "供应商名称")
    @ApiModelProperty(value = "供应商名称(供应商名称)")
    private String supplierName;

    /** 售后类型(refund 退款,return 退款退货,change更换) */
    @Excel(name = "售后类型(refund 退款,return 退款退货,change更换)")
    @ApiModelProperty(value = "售后类型(refund 退款,return 退款退货,change更换) ")
    private String serviceType;

    /** 售后原因 根据类型选择 */
    @Excel(name = "售后原因 根据类型选择")
    @ApiModelProperty(value = "售后原因 根据类型选择(售后原因 根据类型选择)")
    private String serviceReason;

    /** 售货数量 */
    @Excel(name = "售货数量")
    @ApiModelProperty(value = "售货数量(售货数量)")
    private Integer serviceNumber;

    /** 售货金额 */
    @Excel(name = "售货金额")
    @ApiModelProperty(value = "售货金额(售货金额)")
    private Long serviceAmount;

    /** 余额退款（后台可修改，现金退款+余额退款之和不能大于售后金额） */
    @Excel(name = "余额退款" , readConverterExp = "后=台可修改，现金退款+余额退款之和不能大于售后金额")
    @ApiModelProperty(value = "余额退款(后=台可修改，现金退款+余额退款之和不能大于售后金额)")
    private Long serviceBalance;

    /** 现金退款（后台可修改，现金退款+余额退款之和不能大于售后金额） */
    @Excel(name = "现金退款" , readConverterExp = "后=台可修改，现金退款+余额退款之和不能大于售后金额")
    @ApiModelProperty(value = "现金退款(后=台可修改，现金退款+余额退款之和不能大于售后金额)")
    private Long serviceCash;

    /** 图片凭证 */
    @Excel(name = "图片凭证")
    @ApiModelProperty(value = "图片凭证(图片凭证)")
    private String proofImages;

    /** 凭证描述 */
    @Excel(name = "凭证描述")
    @ApiModelProperty(value = "凭证描述(凭证描述)")
    private String proofDesc;

    /** 售后状态(0取消售后,1申请待处理,2处理中,3拒绝售后,4同意售后,,5售后完成) */
    @Excel(name = "售后状态(0取消售后,1申请待处理,2处理中,3拒绝售后,4同意售后,,5售后完成)")
    @ApiModelProperty(value = "售后状态(0取消售后,1申请待处理,2处理中,3拒绝售后,4同意售后,,5售后完成)")
    private String dataStatus;

    /** 申请人ID */
    @Excel(name = "申请人ID")
    @ApiModelProperty(value = "申请人ID(申请人ID)")
    private Long applyUid;

    /**  申请人昵称 */
    @Excel(name = " 申请人昵称")
    @ApiModelProperty(value = " 申请人昵称( 申请人昵称)")
    private String applyNickName;

    /** 联系电话 */
    @Excel(name = "联系电话")
    @ApiModelProperty(value = "联系电话(售后必传)")
    private String applyPhone;

    /** 申请时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "申请时间" , width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "申请时间(申请时间)")
    private Date applyTime;

    /** 客户收货地址 */
    @Excel(name = "客户收货地址")
    @ApiModelProperty(value = "客户收货地址(客户收货地址)")
    private Long customerAddressUid;

    /** 商家收货地址 */
    @Excel(name = "商家收货地址")
    @ApiModelProperty(value = "商家收货地址(商家收货地址)")
    private Long supplierAddressUid;

    /** 修改人 */
    @Excel(name = "修改人")
    @ApiModelProperty(value = "修改人(修改人)")
    private Long updateUser;

    /** 修改人名称 */
    @Excel(name = "修改人名称")
    @ApiModelProperty(value = "修改人名称(修改人名称)")
    private String updateName;

    /** 修改时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "修改时间" , width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "修改时间(退款时间)")
    private Date updateTime;

    /** 处理备注 */
    @Excel(name = "处理备注")
    @ApiModelProperty(value = "处理备注(处理备注)")
    private String remark;

    @ApiModelProperty(value = "快递单号(用户退换货)")
    private String logisticsNo;

    /**
     * 订单明细
     */
    @ApiModelProperty(value = "订单明细")
    private OrderItemVo itemVo;
    /**
     * 客户收货地址信息
     */
    @ApiModelProperty(value = "客户收货地址信息")
    private CustomerAddressVo customerAddressVo;

    /**
     * 供应商收货地址信息
     */
    @ApiModelProperty(value = "供应商收货地址信息")
    private SupplierAddressVo supplierAddressVo;

    /**
     * 平台收货地址信息
     */
    @ApiModelProperty(value = "平台收货地址信息(当supplierUid 等于0时，商家收货地址取这个)")
    private PlatformAddressVo platformAddressVo;


    /**
     * 可申请售后类型
     * @return
     */
    @ApiModelProperty(value = "可申请售后类型")
    private List<ServiceTypeVo> serviceTypeVoList;

    @ApiModelProperty(value = "售后节点信息")
    private List<OrderPostSaleNodeVo> nodeVoList;


    @ApiModelProperty(value = "是否显示取消售后按钮（0不显示1显示）")
    public String getShowCancel(){
        if(ServiceStatusEnum.apply.getKey().equals(dataStatus)
            || ServiceStatusEnum.processing.getKey().equals(dataStatus) ){
            return "1";
        }
        return "0";
    }

    public String getServiceAmountStr(){
        return PriceFormatUtil.format(serviceAmount);
    }

    public String getServiceBalanceStr(){
        return PriceFormatUtil.format(serviceBalance);
    }

    public String getServiceCashStr(){
        return PriceFormatUtil.format(serviceCash);
    }

    public String getServiceTypeName(){
        return ServiceTypeEnum.getNameByKey(serviceType);
    }

    public String getDataStatusName(){
        return ServiceStatusEnum.getNameByKey(dataStatus);
    }

    public String getReasonName(){
        if(ServiceTypeEnum.refund.getKey().equals(serviceType)){
            return ServiceRefundEnum.getNameByKey(serviceReason);
        }else if(ServiceTypeEnum.returnd.getKey().equals(serviceType)){
            return ServiceReturnEnum.getNameByKey(serviceReason);
        }else if(ServiceTypeEnum.change.getKey().equals(serviceType)){
            return ServiceChangeEnum.getNameByKey(serviceReason);
        }
        return "";
    }

    public String getProofImagesOne() {
        if(!StringUtils.isEmpty(proofImages)){
            String[] split = proofImages.split(",");
            return split[0];
        }
        return "";
    }

}
